function reloadTab(){
	jQuery.modal.close();
	jQuery('#escort-option').tabs( "load" , 25 );
}
function openCountryPopup(){
	jQuery('#basic-modal-content-countrysetting').modal({
		onClose:reloadTab
	});
	jQuery("select#countrysetting_code").trigger("liszt:updated");
}

function saveCountrysetting(){
	if(validate()){
		var params = {};
		jQuery("#add-countrysetting-form") .find("select, input[type='checkbox'], input[type='text'], input[type='hidden'], input[type='password'], input[type='submit'], textarea").each(function() {
			if(jQuery(this).attr('type') == 'checkbox'){
				if(jQuery(this).is(':checked')){
					params[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value;
				}
			}else{
				params[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value;
			}
		});
		if(jQuery('#countrysetting_id').val() == ""){
			jQuery.post("./admin/database_definition/countrysettings/ajax_countrysetting_save", params,
				function(data) {
					res = eval('(' + data + ')');
					if(res.result){
						jQuery('#escort-option').tabs( "load" , 25 );
						jQuery.modal.close();
						if(jQuery('#content-body div.alert').length){
							jQuery('#content-body div.alert').remove();
						}
						jQuery('#content-body').prepend('<div class="alert success">'+ res.message+'</div>');
					}else{
						if(jQuery('form#add-countrysetting-form section.item div.alert').length){
							jQuery('form#add-countrysetting-form section.item div.alert').remove();
						}
						jQuery('form#add-countrysetting-form section.item').prepend('<div class="alert error">'+ res.message+'</div>');
					}
				}
			);
		}else{
			jQuery.post("./admin/database_definition/countrysettings/ajax_countrysetting_update", params,
				function(data) {
					res = eval('(' + data + ')');
					if(res.result){
						jQuery('#countrysetting_id').val("");
						jQuery("#countrysetting").val("");
						jQuery('#escort-option').tabs( "load" , 25 );
						jQuery.modal.close();
						if(jQuery('#content-body div.alert').length){
							jQuery('#content-body div.alert').remove();
						}
						jQuery('#content-body').prepend('<div class="alert success">'+ res.message+'</div>');
					}else{
						if(jQuery('form#add-countrysetting-form section.item div.alert').length){
							jQuery('form#add-countrysetting-form section.item div.alert').remove();
						}
						jQuery('form#add-countrysetting-form section.item').prepend('<div class="alert error">'+ res.message+'</div>');
					}
			 	}
			);
		}
	}else{
		return false;
	}
}
function validate(){
	return true;
}
function editCountrysetting(id){
	jQuery.post("./admin/database_definition/countrysettings/ajax_countrysetting_get", { id: id},
		function(data) {
			res = eval('(' + data + ')');
			jQuery('#basic-modal-content-countrysetting').modal({
				onClose:reloadTab
			});
			jQuery('#countrysetting_tax').val(res.tax);
			jQuery('#country_id').val(res.country_id);
			jQuery('#countrysetting_id').val(res.id);
			jQuery("select#country_id").trigger("liszt:updated");
	 	}
	);
	return false;
}
function deleteCountrysetting(id, message){
	confirm(message, function () {
		jQuery.post("./admin/database_definition/countrysettings/ajax_countrysetting_delete", { id: id},
			function(data) {
				jQuery('#escort-option').tabs( "load" , 25 );
				if(jQuery('#content-body div.alert').length){
					jQuery('#content-body div.alert').remove();
				}
				jQuery('#content-body').prepend('<div class="alert success">'+ data.message+'</div>');
		 	}, "json"
		);
		return false;
	});
	return false;
}